#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

Mat src, dst, gray_src;
int t1_value = 50;
int max_value = 255;
char src_title[] = "sourceimage";
char dst_title1[] = "image1";
char dst_title2[] = "image2";
void Canny_Demo(int, void*);

int main() {
  src = imread("../images/2.jpg");
  if (src.empty()) {
    cout << "could not load image.." << endl;
    return -1;
  }
  namedWindow("opencv setup demo", CV_WINDOW_AUTOSIZE);
  imshow("opencv setup demo", src);

  Mat dst1, dst2;

  namedWindow(dst_title1, CV_WINDOW_AUTOSIZE);

  cvtColor(src, gray_src, CV_BGR2GRAY);
  createTrackbar("Threshold Value", dst_title1, &t1_value, max_value,
                 Canny_Demo);
  Canny_Demo(0, 0);

  waitKey(0);
  return 0;
}

void Canny_Demo(int, void*) {
  Mat edge_output;
  blur(gray_src, gray_src, Size(3, 3), Point(-1, -1), BORDER_DEFAULT);
  Canny(gray_src, edge_output, t1_value, t1_value * 2, 3, false);
  dst.create(src.size(), src.type());
  src.copyTo(dst, edge_output);
  imshow(dst_title1, dst);
}